package com.happyfamily.springboot.crowdsourcingplatform.service.wang.impl;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dao.wang.CreditDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.Credit;
import com.happyfamily.springboot.crowdsourcingplatform.model.SysUser;
import com.happyfamily.springboot.crowdsourcingplatform.service.wang.CreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class CreditServiceImpl implements CreditService
{
	@Autowired
	private CreditDao creditDao;

	//门户查询信用分
	@Override
	public SysUser searchCredit(String uaccount)
	{
		return creditDao.searchCredit(uaccount);
	}

	//信用分查询
	@Override
	public Results<Credit> creditList(Integer startP, Integer endP, String starttime, String endtime, HttpServletRequest req)
	{
		SecurityContextImpl securityContext=(SecurityContextImpl)req.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
		String uaccount=securityContext.getAuthentication().getName();
		return Results.success(creditDao.creditCount(starttime,endtime,uaccount).intValue(),creditDao.creditList(startP,endP,starttime,endtime,uaccount));
	}
}
